package com.example.voice;

import com.baidu.aip.speech.AipSpeech;
import org.json.JSONObject;

/**
 * Copyright © 2017年 ziniuxiaozhu. All rights reserved.
 *
 * @Author 临江仙 hzqiuxm@163.com
 * @Date 2017/12/7 0007 17:30
 */
public class AiVoice {

    public static final String APP_ID = "10497099";
    public static final String API_KEY = "NeKNZiZwuU8OcGA0Gjurc28u";
    public static final String API_SECRET = "XwNtNSOX2sbLmu055C8521trSGG5RZSf";


    public static void getAiVoiceFromLocal(){

        //初始化一个语音识别器
        AipSpeech aipSpeech = new AipSpeech(APP_ID,API_KEY,API_SECRET);

        aipSpeech.setConnectionTimeoutInMillis(5000);
        aipSpeech.setSocketTimeoutInMillis(10000);

        //对本地语音识别
        String voicepath = "E:\\testdata\\pcm\\asrTest2.pcm";
        JSONObject asr = aipSpeech.asr(voicepath, "pcm", 8000, null);

        System.out.println("格式化之前的结果：" + asr);

        System.out.println("格式化之后的结果：" + asr.toString());


    }

    public static void getAiVoiceFromNet(){

        String url = "http://www.arrayvip.com/res/8k_test.pcm";
        String callBack = "http://www.arrayvip.com/callback.do";

        AipSpeech aipSpeech = new AipSpeech(APP_ID,API_KEY,API_SECRET);

        aipSpeech.setConnectionTimeoutInMillis(5000);
        aipSpeech.setSocketTimeoutInMillis(10000);

        JSONObject asr = aipSpeech.asr(url, callBack, "pcm", 16000, null);

        System.out.println("语音解析结果：" +asr);

    }

    public static void main(String[] args) {

        AiVoice.getAiVoiceFromLocal();
    }
}
